@tool
extends InventorySlot


@onready var texture_rect: TextureRect = $TextureRect
@onready var label: Label = $Label
@onready var dragable: Dragable = $Dragable


@export var null_texture: Texture2D = null


func __prepare() -> void:
    super.__prepare()

    await ready
    set_item(inventory_item)

func on_amount_changed(item: InventoryItem) -> void:
    label.text = str(item.amount)

func set_item(value: InventoryItem) -> void:
    super.set_item(value)

    if label and texture_rect:
        if inventory_item and inventory_item.source:
            # amount > 1 才显示数字
            label.text = str(inventory_item.amount) if inventory_item.amount > 1 else ""
            texture_rect.texture = inventory_item.source.icon
        else:
            label.text = ""
            texture_rect.texture = null_texture
